using System;
using System.Collections.Generic;

namespace WindowsAPI.Service
{
    internal static class IEnumerableEx
    {
        public static void Foreach<T>(this IEnumerable<T> Enum, Action<T> action)
        {
            foreach(var i in Enum) action(i);
        }

        public static void ForeachParralel<T>(this IEnumerable<T> Enum, Action<T> action)
        {
            foreach(var i in Enum)
                action.BeginInvoke(i, null, null);
        }

        public static IEnumerable<T> ForeachLeazy<T>(this IEnumerable<T> Enum, Action<T> action, bool PreAction = true)
        {
            if(PreAction)
                foreach(var i in Enum)
                {
                    action(i);
                    yield return i;
                }
            else
                foreach(var i in Enum)
                {
                    yield return i;
                    action(i);
                }
        }
    }
}